package IC.AST;

import java.util.LinkedList;

public class Method extends FieldsOrMethod
{
	private boolean _isStatic = false;
	
	private String _id;
	private Type _returnType; //can be null, means void
	private LinkedList<Formal> _formals;
	private ScopeStatement _scope;
	
	public Method (Interval interval, String id, Type returnType, LinkedList<Formal> formals, ScopeStatement scope)
	{
		super(interval);
		_id = id;
		GiveBirth(returnType);
		_returnType = returnType;
		GiveBirth(scope);
		_scope = scope;
		_formals = (formals == null) ? new LinkedList<Formal>() : formals;
		for (Formal formal : _formals)
			GiveBirth(formal);
	}
	
	public Method SetStatic() throws java.lang.Exception 
	{
		if (_isStatic)
			throw new java.lang.Exception("Can't parse Method declaraion, since static is set more then once");
		_isStatic = true;
		return this;
	}
	
	public boolean IsStatic() { return _isStatic; }
	public String GetID() { return new String(_id); }
	public Type GetReturnType() { return _returnType; }
	public LinkedList<Formal> GetFormals() { return _formals; }
	public ScopeStatement GetScope() {return _scope; }
	
	public Object Visit(Visitor visitor) { return visitor.Visit(this); }
}
